package client;

import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.core.client.GWT;

import java.util.*;

/**
 * ContactListService
 *
 * @author Masud Idris
 * @version 1.0
 * @since Dec 18, 2007, 9:56:47 PM
 */
public interface ContactListService extends RemoteService {
  /**
   * Method used to get a list of contacts
   * @return  ArrayList of Contact objects
   *
   * @gwt.typeArgs <client.Contact>
   */
  public ArrayList getContactList();

  /**
   * Method used to echo a list of contacts. This method serves no real purpose other than to
   * demonstrate how to annotate a service method.
   *
   * @param listOfContacts contact list to echo
   * @return  echoed contact list
   *
   * @gwt.typeArgs listOfContacts <client.Contact>
   * @gwt.typeArgs <client.Contact>
   */
  public ArrayList echoContactList(ArrayList listOfContacts);

  /**
   * Utility/Convenience class.
   * Use ContactListService.App.getInstance() to access static instance of ContactListServiceAsync
   */
  public static class App {
    private static ContactListServiceAsync ourInstance = null;

    public static synchronized ContactListServiceAsync getInstance() {
      if (ourInstance == null) {
        ourInstance = (ContactListServiceAsync) GWT.create(ContactListService.class);
        ((ServiceDefTarget) ourInstance).setServiceEntryPoint(
                GWT.getModuleBaseURL() + "ContactListApp/ContactListService");
      }
      return ourInstance;
    }
  }
}
